package de.uni_mannheim.informatik.ai.dame_ai.util;

import java.awt.FlowLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;


/**
 * A simple Modal Dialog that allows the User to a Question with yes or no.
 * @author Martin Boelle
 *
 */
public class DecisionDialog extends PopupDialog {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private boolean decision=false;

	/**
	 * @param owner The owner of the dialog. He will be disabled until the user responds.
	 * @param title The title for the dialog frame.
	 * @param question The question which will be diplayed to the user.
	 */
	public DecisionDialog(Window owner, String title, String question) {
		super(owner, title, question);
		JButton butYes = new MinSizeButton("Ja", MIN_BUTTON_WIDTH);
		JButton butNo = new MinSizeButton("Nein", MIN_BUTTON_WIDTH);
		butPan.add(butYes);
		butPan.add(butNo);
		((FlowLayout)butPan.getLayout()).setHgap(20);
		butYes.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				decision=true;
				dispose();
			}
		});
		
		butNo.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				decision=false;
				dispose();
			}
		});
	}
	
/**
 * Makes a modal dialog disapear and returns the users decision.
 * @param owner The owner of the dialog. He will be disabled until the user responds.
 * @param title The title for the dialog frame.
 * @param question The question which will be diplayed to the user.
 * @param center The Position where the center of the dialog should be placed.
 * @return the users decision: true->Yes, false->No
 */
	public static boolean askQuestion(Window owner, String title, String question){
		DecisionDialog dd= new DecisionDialog(owner, title, question);
		dd.setVisible(true);
		return dd.decision;
	}

}